package collection;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionOpenDemo {
    public static void main(String[] args) {
        Collection c1 = new ArrayList();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);//[java, c++, .net, Android, iso, java]

        Collection c2 = new ArrayList();
        c2.add("Android");
        c2.add("iso");
        c2.add("java");
        System.out.println("c2:"+c2);
        //
        c1.addAll(c2);
        System.out.println("c1:"+c1);
        System.out.println("c2:"+c2);
        //包含
        Collection c3 = new ArrayList();
        c3.add("java");
        c3.add("c++");
        c3.add("php");
        System.out.println("c3"+c3);
        boolean contains = c1.contains(c3);
        System.out.println("c1是否包含c3："+contains);

        //取交集：c1中仅保留与c3中共有的元素,而c3不变
        c1.retainAll(c3);
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);

        //删交集：将c1中与c3共有的元素删除，c3不变
        c1.removeAll(c3);
        System.out.println("c1:"+c1);
        System.out.println("c3:"+c3);

    }
}
